const str = `1 21 3
4 5 6
7 8 9`
function transform(str) {
    let arr1 = str.split('\n')
    // console.log(arr1);
    let result=''
   arr1.forEach(element => {
        result.concat(...element.split(" ")) 
    });
    console.log(result);
    
}
transform(str)